package cn.aitstone.controller;

import cn.aitstone.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
/**
 * @Description: 订单接口
 * @Author: Sheldon
 * @Version: 1.0
 * @Date:  2022/7/27 20:38
 */
@RestController
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallbackMethod")
    @GetMapping("/getByUserId/{id}")
    public User getByUserId(@PathVariable Long id){
        String url = "http://user-server/user/" + id;
        return restTemplate.getForObject(url, User.class);
    }


    public User fallbackMethod(@PathVariable Long id){
        return User.builder().id(-1L).intro("用户服务不可用").build();
    }
}
